﻿package com.fecesaids.greatgame.inventory {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import com.fecesaids.greatgame.GreatGame;
	public class InventoryItem extends Sprite{
		private var _myIsSelected:Boolean = false;
		private var _myName:String;
		private var _myBaseItem:String;
		private var _myImage:Sprite;
		private var _myActions:Array;
		private var _myActionLabels:Array;
		
		public function InventoryItem(invData:Array):void{
			_myActionLabels = [];
			_myName = invData[0];
			_myBaseItem = invData[1];
			_myImage = invData[2];
			addChild(_myImage);
			//_myImage.parent = this;
			if(invData.length > 3){
				_myActions = [];
				_myActions = invData[3];
				parseLabels();
			}
		}
		public function getBaseName():String{
			return _myBaseItem;
		}
		private function parseLabels():void {
			var numElements = _myActions.length;
			for(var i=0; i<numElements; i++) {
				_myActionLabels.push(_myActions[i][0]);
			}
		}
		public function doAction(actionToDo:String):void{
			var numElements = _myActions.length;
			var gInstance = GreatGame.getInstance();
			for(var i=0; i<numElements; i++) {
				if(_myActions[i][0] == actionToDo){
					gInstance.doEvent(_myActions[i]);
				}
			}
		}
		public function doUse():void{
			doAction(_myActionLabels[0]);
		}
		
		public function getPosX():int{
			return this.x;
		}
		public function getPosY():int{
			return this.y;
		}
		public function setPos(posX:int, posY:int):void{
			this.x = posX;
			this.y = posY;
		}
		public function getWidth():Number{
			return this.width;
		}
		public function getHeight():Number{
			return this.height;
		}
		public function getOptions():Array{
			if(_myActionLabels.length > 0){
				return _myActionLabels;
			}
			else
				return ["Cancel"];
		}
	}
}